package com.lujianfei.ann.utils;

import java.util.Random;

import com.lujianfei.ann.bean.MaxMinResult;

public class MathTool {

	static MathTool instance = new MathTool();
	

	public static MathTool getInstance() {
		return instance;
	}
	
	private MathTool() {
		
	}

	Random random = new Random(System.currentTimeMillis());

	public int getRandom(int start, int end) {
		return random.nextInt(end + 1 - start) + start;
	}

	public double getGaussian() {
		return random.nextGaussian();
	}
	
	public MaxMinResult getMaxMin(int[] numbers) {
		MaxMinResult mNormalizeResult = new MaxMinResult();
		for (Integer number : numbers) {
			if (number > mNormalizeResult.getMax()) {
				mNormalizeResult.setMax(number);
			}
			if (number < mNormalizeResult.getMin()) {
				mNormalizeResult.setMin(number);
			}
		}
		return mNormalizeResult;
	}

	public double normalize(double num, MaxMinResult maxMinResult) {
		return (double) (num - maxMinResult.getMin()) / (double) (maxMinResult.getMax() - maxMinResult.getMin());
	}
	
	public double denormalize(double num, MaxMinResult maxMinResult) {
		return num * (double)(maxMinResult.getMax() - maxMinResult.getMin()) + maxMinResult.getMin();
	}
}
